<template>
  <div class="settings-page">
    <header>
      <i class="fa fa-angle-left" @click="navigateToMyPage"></i>
      <p>设置</p>
    </header>

    <div class="settings-content">
      <!-- 设置选项列表 -->
      <div class="settings-list">
        <!-- 收货地址管理 -->
        <div class="setting-item" @click="navigateTo('/userAddress')">
          <div class="setting-info">
            <i class="fa fa-map-marker setting-icon"></i>
            <span class="setting-name">收货地址管理</span>
          </div>
          <i class="fa fa-angle-right setting-arrow"></i>
        </div>

        <!-- 账号与安全 -->
        <div class="setting-item" @click="navigateTo('/alterUserInfo')">
          <div class="setting-info">
            <i class="fa fa-shield setting-icon"></i>
            <span class="setting-name">账号与安全</span>
          </div>
          <i class="fa fa-angle-right setting-arrow"></i>
        </div>
      </div>

      <!-- 退出登录按钮 -->
      <div class="logout-container">
        <button class="logout-button" @click="handleLogout">退出当前账号</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { useUserStore } from '../store/pinia_store_user';

const router = useRouter();
const userStore = useUserStore();

// 导航到指定路由
const navigateTo = (path) => {
  router.push(path);
};

// 导航到"我的"页面
const navigateToMyPage = () => {
  router.push('/userInfo');
};

// 处理退出登录
const handleLogout = () => {
  if (confirm('确认要退出当前账号吗？')) {
    userStore.logout();
    // 退出后跳转到登录页面
    router.push('/login');
  }
};
</script>

<style scoped>
.settings-page {
  background-color: #f5f5f5;
  min-height: 100vh;
}

header {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
  color: #fff;
  font-size: 4.8vw;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

header .fa-angle-left {
  font-size: 6vw;
  position: absolute;
  left: 4vw;
  cursor: pointer;
}

.settings-content {
  padding-top: 14vw;
  padding-bottom: 20vw;
}

.settings-list {
  background-color: #fff;
  margin: 3vw 0;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4vw 4vw;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.setting-info {
  display: flex;
  align-items: center;
}

.setting-icon {
  color: #0097ff;
  font-size: 5vw;
  margin-right: 3vw;
}

.setting-name {
  font-size: 4vw;
  color: #333;
}

.setting-arrow {
  color: #999;
  font-size: 4vw;
}

.logout-container {
  margin-top: 8vw;
  padding: 0 4vw;
}

.logout-button {
  width: 100%;
  padding: 3vw 0;
  background-color: #fff;
  border: none;
  border-radius: 1vw;
  color: #ff5252;
  font-size: 4vw;
  font-weight: bold;
  cursor: pointer;
}

.logout-button:active {
  background-color: #f5f5f5;
}
</style> 